package com.kxz.Controller;

import com.kxz.pojo.Student;
import com.kxz.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class StudentController {
    @Autowired
    StudentRepository studentRepository;

    //增
    @PostMapping("/student")
    public Student addStudent(Student student){
        Student student1=studentRepository.save(student);
        return student1;
    }
    //删
    @DeleteMapping("/student/{gid}")
    public void deleteStudent(@PathVariable("gid") Integer gid){
        studentRepository.deleteById(gid);
    }
    //改
    @PutMapping("/student")
    public Student updateStudent(Student student){
        Student student1=studentRepository.save(student);
        return student1;
    }
    //查
    @GetMapping("/student/{id}")
    public Student selectStudent(@PathVariable("id") Integer id){
        Student student=studentRepository.findById(id).get();
        return student;
    }
}
